package com.zhongfl.crm.api.view;

import com.zhongfl.crm.model.LxDepartment;
import com.zhongfl.crm.service.LxDepartmentService;
import org.springframework.web.bind.annotation.*;
import tech.heptagram.core.common.rest.ResponseResult;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 向日葵
 * @Date 2018/9/20
 */
@RestController
@RequestMapping("/api/dep")
public class LxDepartmentApiController {

    @Resource
    private LxDepartmentService lxDepartmentService;

    /**
     * 根据父id获取子阿米巴
     * @param parentId 父ID
     * @return 子阿米巴
     */
    @PostMapping("/list/{parentId}")
    public ResponseResult<List<LxDepartment>> findByParentId(@PathVariable Long parentId) {
        List<LxDepartment> departments = lxDepartmentService.findByParentId(parentId);
        return new ResponseResult<>(departments);
    }

    /**
     * 根据励销ID查询阿米巴信息
     */
    @GetMapping("/query/lxId/{lxId}")
    public ResponseResult<LxDepartment> findAmiba(@PathVariable Long lxId) {
        LxDepartment department = lxDepartmentService.findByLxId(lxId);
        return new ResponseResult<>(department);
    }

    @GetMapping("/queryAll")
    public ResponseResult<List<LxDepartment>> findAllDepartment(){
        List<LxDepartment> departments = lxDepartmentService.findAllDepartment();
        return new ResponseResult<>(departments);
    }

    @PostMapping("/updateMatchAmiba")
    public ResponseResult updateMatchAmiba(@RequestBody LxDepartment lxDepartment) {
        lxDepartmentService.updateMatchAmiba(lxDepartment);
        return new ResponseResult();
    }

}
